package com.freemyleft.left.zapp.selectimage.adapter;

import android.graphics.Bitmap;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


public class ZhyViewHolder {
	private final SparseArray<View> mViews;
	private View mConvertView;

	ZhyViewHolder(View convertView) {
		this.mViews = new SparseArray<View>();
		mConvertView = convertView;
	}
	/**
	 * 通过控件的Id获取对于的控件，如果没有则加入views
	 *
	 * @param viewId
	 * @return
	 */
	public <T extends View> T getView(int viewId) {
		View view = mViews.get(viewId);
		if (view == null) {
			view = mConvertView.findViewById(viewId);
			mViews.put(viewId, view);
		}
		return (T) view;
	}

	/**
	 * 为TextView设置字符�?
	 *
	 * @param viewId
	 * @param text
	 * @return
	 */
	public View setText(int viewId, String text) {
		TextView view = getView(viewId);
		view.setText(text);
		return view;
	}
	/**
	 * 为TextView设置字符�?
	 *
	 * @param viewId
	 * @param text
	 * @return
	 */
	public ZhyViewHolder setTextColor(int viewId, int text) {
		TextView view = getView(viewId);
		view.setTextColor(text);
		return this;
	}
	/**
	 * 为ImageView设置图片
	 *
	 * @param viewId
	 * @param drawableId
	 * @return
	 */
	public ZhyViewHolder setImageResource(int viewId, int drawableId) {
		ImageView view = getView(viewId);
		view.setImageResource(drawableId);

		return this;
	}
	public ZhyViewHolder setVisibility(int viewId, int visibility){
		View view = getView(viewId);
		view.setVisibility(visibility);
		return this;
	}

	/**
	 * 为ImageView设置图片
	 *
	 * @param viewId
	 * @return
	 */
	public ZhyViewHolder setImageBitmap(int viewId, Bitmap bm) {
		ImageView view = getView(viewId);
		view.setImageBitmap(bm);
		return this;
	}
	/**
	 * 为View更换背景色
	 */
	public ZhyViewHolder setBackColor(int viewId, int color, int index) {
		TextView view = getView(viewId);
		view.setBackgroundColor(color);
		return this;
	}


}
